package com.allen.retrofit2_rxjava2.view.selectimageview.adapter;

import java.util.List;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.allen.retrofit2_rxjava2.R;
import com.allen.retrofit2_rxjava2.view.selectimageview.entity.AlbumInfo;
import com.allen.retrofit2_rxjava2.view.selectimageview.utils.RotateImageViewAware;
import com.allen.retrofit2_rxjava2.view.selectimageview.utils.ThumbnailsUtil;
import com.allen.retrofit2_rxjava2.view.selectimageview.utils.UniversalImageLoadTool;

/**
 * @author 作者： Administrator
 *
 * @version 创建时间：2014年9月1日下午11:26:43
 */
public class PhotoListAdapter extends BaseAdapter {
	private List<AlbumInfo> list;
	private ViewHolder holder;
	private Context context;

	public PhotoListAdapter(Context context, List<AlbumInfo> list) {
		this.context = context;
		this.list = list;
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return position;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@SuppressLint("InflateParams")
    @Override
	public View getView(int position, View convertView, ViewGroup parent) {
		AlbumInfo albumInfo = list.get(position);
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = LayoutInflater.from(context).inflate(R.layout.item_photo_list, null);
			ImageView image = (ImageView) convertView
					.findViewById(R.id.iv_folder);
			TextView text = (TextView) convertView.findViewById(R.id.tv_info);
			TextView num = (TextView) convertView.findViewById(R.id.tv_num);
			holder.image = image;
			holder.text = text;
			holder.num = num;
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		UniversalImageLoadTool.disPlay(
				ThumbnailsUtil.MapgetHashValue(albumInfo.getImage_id(),
						albumInfo.getPath_file()),
				new RotateImageViewAware(holder.image, albumInfo
						.getPath_absolute()), R.mipmap.defult_head);
		holder.text.setText(albumInfo.getName_album());
		holder.num.setText("(" + list.get(position).getList().size() + "张)");
		return convertView;
	}

	public class ViewHolder {
		public ImageView image;
		public TextView text;
		public TextView num;
	}
}
